package com.bwie.parkdemo.mvvm.model;

import android.content.Context;

import com.bwie.lib_core.base.BaseEntity;
import com.bwie.lib_core.mvvm.base.BaseModel;
import com.bwie.lib_core.network.HttpRetrofitFactory;
import com.bwie.lib_core.network.HttpType;
import com.bwie.parkdemo.dao.LoginUserServe;
import com.bwie.parkdemo.mvvm.model.entity.AppointDepartmentEntity;
import com.bwie.parkdemo.mvvm.model.entity.DepartmentEntity;
import com.bwie.parkdemo.mvvm.model.entity.DepartmentUserEntity;
import com.bwie.parkdemo.mvvm.model.entity.LoginEntity;

import io.reactivex.Observable;
import okhttp3.RequestBody;

/**
 *部门接口相关操作model
 * */
public class DepartmentModel extends BaseModel{

    //请求已分组接口
    @Override
    public Observable<BaseEntity> request(RequestBody... bodyes) {
        Observable<DepartmentUserEntity> requestSelDepartmentUser =
                HttpRetrofitFactory.getInstance().factory(HttpType.TOKENINTERFACE)
                        .getRetrofit().create(Api.class).requestSelDepartmentUser();
        return changeOB(requestSelDepartmentUser);
    }

    //请求未分组接口
    public Observable<BaseEntity>requestUnDepartment(){
        Observable<DepartmentUserEntity> requestSelDepartmentUser =
                HttpRetrofitFactory.getInstance().factory(HttpType.TOKENINTERFACE)
                        .getRetrofit().create(Api.class).requestUNSelDepartmentUser();
        return changeOB(requestSelDepartmentUser);
    }

    //请求全部部门接口
    public Observable<BaseEntity>requestDepartment(RequestBody body){
        Observable<DepartmentEntity>source = HttpRetrofitFactory.getInstance()
                .factory(HttpType.TOKENINTERFACE).getRetrofit()
                .create(Api.class).requestDepartment(body);
        return changeOB(source);
    }

    //请求获取本地数据库中保存的用户信息
    public LoginEntity.Values requestUser(Context ctx){
        return new LoginUserServe(ctx).selUser();
    }

    //指定员工部门请求
    public Observable<BaseEntity>requestAppointDepartment(RequestBody body){
        Observable<AppointDepartmentEntity>source = HttpRetrofitFactory.getInstance()
                .factory(HttpType.TOKENINTERFACE).getRetrofit().create(Api.class)
                .requestAppointDepartment(body);
        return changeOB(source);
    }

    @Override
    public void cleared() {

    }
}
